package org.academic.texteditor.gui.component.listener;

import java.awt.Component;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.text.JTextComponent;

public class FocusKeyListener implements KeyListener {

	public void keyPressed(KeyEvent event) {
		Component component = event.getComponent();
		if (component instanceof JTextComponent) {
			//clear text with CTRL+BACKSPACE
			if (event.isControlDown() && event.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
				((JTextComponent) component).setText("");
			}
		}
		//change focus using ENTER
		if (event.getKeyCode() == KeyEvent.VK_ENTER) {
			component.transferFocus();
		}
	}

	public void keyReleased(KeyEvent event) {
		
	}

	public void keyTyped(KeyEvent event) {
		
	}

}

